package CtrLayer;
import ModelLayer.*;

/**
 * ItemCtr collect and control methods related to class Item and class ItemContainer. 
 * 
 * @author Gruppe 3 
 * @version 20-12-2011
 */
public class ItemCtr
{
    private ItemContainer itemContainer;
    private Item item;
    private static ItemCtr instance;
    private PartOrder partOrder;

    /**
     * Constructs an object of class ItemCtr and intialize itemContainer. 
     */
    
    public ItemCtr()
    {
       itemContainer = itemContainer.getInstance();
    }
    
    public static ItemCtr getInstance()
    {
        if(instance==null)
        {
            instance = new ItemCtr();
        }
        return instance;
    }
    
    /**
     * Searches the itemContainer for an item using barCode and returns the object item, creates a new object partOrder
     * and adds the object item searched for to the partOrder. Adds the object partOrder to an object order.
     * 
     * @param barCode, the barCode of the item wished searched for.
     * @param quantity, the quantity of the item bought.
     * @param discount, the discount on the partOrder in %.
     * @param order2, the order the partOrder shall be added to. 
     */
    
    public void scanBarCode(String barCode, int quantity, double discount, Order order)
    {
        Item item = findItem(barCode);
        partOrder = new PartOrder(item, quantity, discount);
        order.addToOrder(partOrder);

    }

    /**
     * Searches the item container for an item object using barCode and returns and object of the type Item.
     * 
     * @param barCode, the barCode of the item to search for.
     * @return item, the item with a matching barCode.
     */
    
    public Item findItem(String barCode)
    {
        Item item = itemContainer.findItem(barCode);
        return item;
    }
    
    /**
     * Creates an new item object and adds it to the itemContainer.
     * 
     * @param barCode, the barCode associated with the item.
     * @param itemName, name of the item.
     * @param description, short description of the item.
     * @param retailPrice, price in store in kr.
     * @param buyingPrice, price at supplier in kr.
     * @param location, the items location in the warehouse.
     * @param discount, discount on the item in %. 
     * @param minAmount, minimum amount allowed in stock.
     * @param restockAmount, amount to restock the item to if minimum amount is reaches. 
     * @param amount, amount currently in stock. 
     */

    public void createItem(String barCode, String itemName, String description, double retailPrice, double buyingPrice, String location, double discount, int minAmount, int restockAmount, int amount)
    {
        item = new Item(barCode, itemName, description, retailPrice, buyingPrice, location, discount, minAmount, restockAmount, amount); 
        itemContainer.addItem(item);
    }
    
    public PartOrder getPartOrder()
    {
    	return partOrder;
    }
    
    

}
